function setupDetailFileTap(idStr){
	mui('#'+idStr+' .fileLine').each(function (index,element) {
		var detailImg = element.query
		if (this.querySelector('.photo')) {
			this.querySelector('.detailImg').addEventListener('tap',imgItemTapped)
			this.querySelector('.fileName').addEventListener('tap',imgItemTapped)
			return
		}
		element.addEventListener('tap',fileTapped)
	})
	mui('#'+idStr+' .photo').each(function (index,element) {
		element.addEventListener('error',function(){
			this.setAttribute('data-exist',"No")
		})
	})
	mui('#'+idStr+' .onlyImg img').each(function (index,element) {
		element.addEventListener('error',function(){
			this.removeAttribute('data-preview-group')
			this.removeAttribute('data-preview-src')
			this.parentNode.addEventListener('tap',function(){
				mui.toast('图片不存在')
			})
		})
	})
}
function getDetailFileHtml(valueStr,group,TomcatUrl,path){
	if (valueStr == '' || !valueStr) {
		return ''
	}
	var fileArr = valueStr.split(',')
	var html = ''
	var hasOther = false
	for (var j = 0; j < fileArr.length;j++) {
		var oneUrl = fileArr[j]
		if (oneUrl == '') {
			continue
		}
		if (path && oneUrl.indexOf('Fileupdate/images/')==-1) {
			oneUrl = 'Fileupdate/images/'+path+oneUrl
		}
		var type = detailFileTypeIcon(oneUrl)
		if (type == 'img') {
			html +='<div class="onlyImg"><img src="'+TomcatUrl +'/'+oneUrl+'"  data-preview-group="'+group+'" data-preview-src="" /></div>';
		}else{
			hasOther = true
			break
		}
	}
	//console.log(html)
	if (!hasOther) {
		return html
	}
	var html = ''
	for (var j = 0; j < fileArr.length;j++) {
		var oneUrl = fileArr[j]
		if (oneUrl == '') {
			continue
		}
		if (path && oneUrl.indexOf('Fileupdate/images/')==-1) {
			oneUrl = 'Fileupdate/images/'+path+oneUrl
		}
		var type = detailFileTypeIcon(oneUrl)
		var iconStr = '<div class="detailImg"><img src="../../dependence/teach/images/'+type+'.svg"/></div>';
		if (type == 'img') {
			iconStr += '<div class="detailImg"><img class="photo" src="'+
				TomcatUrl+'/'+oneUrl +'" data-preview-group="1" data-preview-src="" /></div>';
		}
		var index = oneUrl.lastIndexOf("\/");
		var fileName=oneUrl.substring(index+1,oneUrl.length);
		html +='<div class="fileLine" data-url="'+TomcatUrl +'/'+oneUrl+'">'+iconStr+
			'<div class="fileName mui-ellipsis">'+fileName+'</div>'+'</div>';
	}
	return html
}

function detailFileTypeIcon(url){
	var icon = ''
	url = url.toLowerCase()
	if (url.endsWith(".pdf")) {
		icon = 'pdf'
	}else if (url.endsWith(".png")||url.endsWith(".jpg")||url.endsWith(".jpeg")||url.endsWith(".gif")||url.endsWith(".bmp")) {
		icon = 'img'
	}else if (url.endsWith(".doc") || url.endsWith(".docx")) {
		icon = 'word'
	}else if (url.endsWith(".ppt") || url.endsWith(".pptx")) {
		icon = 'ppt'
	}else if (url.endsWith(".txt") || url.endsWith(".json")) {
		icon = 'txt'
	}else{
		icon = 'file'
	}
	return icon
}

function fileTapped(){
	
	var url = this.getAttribute('data-url')
	var fileType = detailFileTypeIcon(url)
	if (fileType == 'img') {
		return;
	}
	var label = this.querySelector('.fileName').innerText
	var pageName = ''
	switch (fileType){
		case "pdf":
		case "word":
		case "ppt":
			pageName = '../../FilePreview/pdfReader.html'
			break;
		case "txt":
			pageName = '../filePreview.html'
			break;
		default:
			break;
	}
	if (pageName == '') {
		mui.toast('暂不支持此类型文件')
		return
	}
	mui.checkUrlReal(url,function(){
		var webview = plus.webview.create(pageName, pageName, {
			background: '#fff',
			statusbar: {
				background: '#fff'
			}
		}, {
			'title': label,
			'fileUrl': url
		});
		plus.navigator.setStatusBarBackground('#fff');
		plus.navigator.setStatusBarStyle('dark');
		webview.show('fade-in');
		webview.addEventListener('close', function() {
			plus.navigator.setFullscreen(false);
			plus.navigator.setStatusBarBackground('#24AF96');
			plus.navigator.setStatusBarStyle('light');
			plus.screen.lockOrientation("portrait-primary");
		});
	},function(){
		mui.toast('文件不存在')
	})
}
function imgItemTapped(){
	var dom = this.parentNode.querySelector('.photo')
	if (dom.getAttribute('data-exist')!= "No") {
		mui.trigger(dom,'tap')
	}else{
		mui.toast('图片不存在')
	}
}